//
//  NewsUserView.m
//  Fireball
//
//  Created by 俞渊华 on 2017/12/11.
//  Copyright © 2017年 俞渊华. All rights reserved.
//

#import "NewsUserView.h"

@interface NewsUserView ()
@property(nonatomic, strong)UIButton *userHeader;
@property(nonatomic, strong)UILabel *userNameLabel;
@property(nonatomic, strong)UILabel *timeLabel;
@property(nonatomic, strong)UIButton *attentionButton;
@property(nonatomic, strong)UIView *lineView;
@end

@implementation NewsUserView

-(instancetype)initWithFrame:(CGRect)frame{
    if ([super initWithFrame:frame]) {
        self.backgroundColor = [UIColor whiteColor];
        
        self.userHeader = [UIButton buttonWithType:UIButtonTypeCustom];
        self.userHeader.clipsToBounds = YES;
        [self addSubview:self.userHeader];
        self.userHeader.backgroundColor = [UIColor xm_MainColor];
        
        self.lineView = [[UIView alloc]init];
        [self addSubview:self.lineView];
        
        self.userNameLabel = [[UILabel alloc]init];
        self.userNameLabel.font = [UIFont xm_font:14.0];
        self.userNameLabel.textColor = [UIColor xm_middleColor];
        [self addSubview:self.userNameLabel];
        
        self.timeLabel = [[UILabel alloc]init];
        self.timeLabel.font = [UIFont xm_font:12.0];
        self.timeLabel.textColor = [UIColor xm_somberColor];
        [self addSubview:self.timeLabel];
        
        
        self.attentionButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.attentionButton setTitle:@"+关注" forState:UIControlStateNormal];
        [self.attentionButton setTitleColor:[UIColor xm_MainColor] forState:UIControlStateNormal];
        self.attentionButton.titleLabel.font = [UIFont xm_font:13.0];
        
        self.attentionButton.clipsToBounds = YES;
        self.attentionButton.layer.cornerRadius = 12.0;
        self.attentionButton.layer.borderWidth = 0.8;
        self.attentionButton.layer.borderColor = [UIColor xm_MainColor].CGColor;

        [self addSubview:self.attentionButton];
        
    }
    return self;
}
-(void)setDetailModel:(AticleDetailModel *)detailModel{
    _detailModel = detailModel;
    [self.userHeader xm_setImageWithURL:_detailModel.UserLogo forState:UIControlStateNormal placeholderImage:nil];
    self.userNameLabel.text = _detailModel.Author;
    self.timeLabel.text = @"42分钟前";
}
-(void)layoutSubviews{
    [super layoutSubviews];
    
    [self.userHeader mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.bottom.mas_equalTo(self);
        make.width.mas_equalTo(self.userHeader.mas_height);
    }];
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.userHeader.mas_right).offset(10);
        make.centerY.mas_equalTo(self.userHeader);
        make.height.mas_equalTo(@6);
    }];
    [self.userNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.userHeader.mas_right).offset(10);
        make.bottom.mas_equalTo(self.lineView.mas_top);
    }];
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.userHeader.mas_right).offset(10);
        make.top.mas_equalTo(self.lineView.mas_bottom);
    }];
    [self.attentionButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(60, 24));
        make.centerY.mas_equalTo(self);
        make.right.mas_equalTo(self).offset(-20);
    }];
    
    self.userHeader.layer.cornerRadius = self.height * 0.5;

    
}
-(void)drawRect:(CGRect)rect{
    [super drawRect:rect];
}


@end
